package com.yuhanginfo.modules.web.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yuhanginfo.common.service.WebCrudService;
import com.yuhanginfo.modules.web.util.WebUserUtils;
import com.yuhanginfo.modules.web.dao.WebClassDao;
import com.yuhanginfo.modules.web.entity.WebClass;

@Service
@Transactional(readOnly = true)
public class WebClassService extends WebCrudService<WebClassDao, WebClass> {
	@Autowired
	private WebClassDao webClassDao;
	
	public List<WebClass> getFirstClasses() {
		return webClassDao.getFirstClasses();
	}
	
	public List<WebClass> getClassesByParentId(String parentId){
		return webClassDao.getClassesByParentId(parentId);
	}
	
	public List<WebClass> getAllClasses(){
		List<WebClass> webClassList=(List<WebClass>)WebUserUtils.getCache("allClasses");
		if(webClassList==null) {
			webClassList=getFirstClasses();
			for(WebClass classes:webClassList) {
				
				
				List<WebClass> secondList=getClassesByParentId(classes.getId());
				classes.setClassList(secondList);
				for(WebClass secondClass:secondList) {
					List<WebClass> thirdList =getClassesByParentId(secondClass.getId());
					secondClass.setClassList(thirdList);
				}
			}
			WebUserUtils.putCache("allClasses",webClassList);
		}
		return webClassList;
	}
}
